$(document).ready(function(){
	$('pageSelect').change(function(){
		$(this).closest('form').submit();
	});
	var page = $(this).data('page');
	var segment =$(this).data('segment');
	$(document).on('click','#btndel',function(e){
		e.preventDefault();
		var btn = $(this);
		var data ="<label class='alert alert-danger'>Bạn có chắc muốn xóa SV náy</label>"
		$('#divDel').find('p').html(data);
		$('#divDel').dialog('open');
	});
	$('#divDel').dialog({
		resizable: false,
		height :300,
		width : 500,
		modal:true,
		autoOpen: false,
		title:"Xoá sinh viên",
		 show: {
		        effect: "Slide",
		        duration: 1000
		      },
		      hide: {
		        effect: "Slide",
		        duration: 1000
		      },
		buttons:[
		         {
		         html: "<span class='glyphicon glyphicon-ok'>Xóa </span>",
		         click: function(){
		        	 xoa(this);
		         }
		         },
		         {
		        	 html: "<span class='glyphicon glyphicon-remove'>Hủy </span>",
		        	 click: function(){
		        		 $(this).dialog("close");
		        	 }
		         },
		         ]
	});
	function xoa(btn){
		var mssv = $('#btndel').data('mssv');
		var malop=$('#MaLop').val();
		var param = {'masv':mssv};
		
		var img = "<img src='images/ajax_loading.gif' />"
		var url ="XoaSV.php";
			$.ajax({
				url : url,
				data: param,
				type: "POST",
				dataType: "HTML",
				error: function(){},
				beforeSend: function(){
					$(btn).hide();
					$(btn).after(img);
				},
				complete:function(){
					$(btn).show();
					$(btn).next().remove();
				},
				success: function(data){
					if(data == "OK"){
						$('#divDel').dialog("close");
						
						var malop =$('#MaLop').val();		
						reload(page,malop,segment);
						
					}else{
						$('#divDel').find('p').html(data);
					}
				}
			});

	}
function reload(page,malop,segment){
	var pagam ={'malop':malop,'page':page,'segment':segment};
	var url ="timlop.php";
	var img = "<img src='images/ajax_loading.gif' />"
		$.ajax({
			url : url,
			data: pagam,
			type: "POST",
			dataType: "HTML",
			error: function(){},
			beforeSend: function(){
			
			},
			complete :function(){
				
			},
			success: function(data){
				if(data){
					$('#danhsach').html(data);
				}else{
					$('#danhsach').html("<div class='alert alert-warning'>Không tìm thấy sinh viên </div>");
				}
			}
		});

}
});